<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">提交</button>
    <script>
        let btn = document.getElementById('btn');
        // function handle(){
        //     console.log('向后端发请求');
        //     //将按钮置灰
        //     btn.disabled = true;
        //     //过1s后再启用
        //     setTimeout(() => {
        //         btn.disabled = false;
        //     }, 2000);
        // }
        function handle(){
            console.log('向后端发请求',this);
        }
        btn.addEventListener('click',debounce(handle,1000))
        function debounce(fn,wait){
                var timer = null;
            return function(...arr){
                clearTimeout(timer)
                var timer = setTimeout(()=>{
                    fn.call(this,...arr)
                },wait)
            }
        }
    </script>
</body>
</html>